
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box">
        <div class="icon-box">
          <span class="iconfont icon-yuangong" />
        </div>
        <span class="text" style="margin-right: 10px">人事统计报告</span>
        <a-month-picker
          style="width: 195px"
          placeholder="请选择年月"
          v-model="setYearMonthValue"
          @change="handleDateChange"
          :format="dateFormat"
        />
        <a-button type="primary" @click="initAxis" style="margin-left: 10px" icon="search">查询</a-button>
      </div>
    </div>

    <div class="table-content">
      <div class="handle-bar">
        <!-- <a-button class="export-btn">导出</a-button> -->
      </div>
      <a-table :scroll="{ y: 500 }" :columns="fieldList" :data-source="tableList" bordered :pagination="false">
      </a-table>
    </div>

    <div class="analysis">
      <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="analysisBu1" /></div
        ></a-col>
      </a-row>
    </div>

    <div class="content"></div>
  </div>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  /** 客户总量分析 */
  name: 'HrReportAll1',
  data() {
    return {
      loading: false,
      isAllData: this.$store.getters.buData == 'allhrdata' ? true : false,
      chartAnalysis1: null,
      analysis1Option: {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
        },
        dataZoom: [
          {
            // 控制图表左右滑动
            width: '15',
            type: 'slider',
            show: false, //flase直接隐藏图形
            xAxisIndex: [0],
            left: 33, //滚动条靠左侧的百分比
            bottom: 40,
            height: 20, //组件高度
            start: 0, //滚动条的起始位置
            showDataShadow: false, //是否显示数据阴影
            showDetail: false, //是否显示想洗数值信息
          },
          {
            type: 'inside',
            show: true,
            xAxisIndex: [0],
            start: 0, //滚动条的起始位置
            end: 0.25, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
        ],
        legend: {
          data: [],
          bottom: 0,
        },
        toolbox: {
          show: true,
          orient: 'vertical',
          left: 'right',
          top: 'center',
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        xAxis: [
          {
            type: 'category',
            data: ['离职人数', '入职人数', '月初在职人数', '月末在职人数'],
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
        series: [],
      },
      postParams: {}, // 筛选参数
      dataIndex: null,
      list: [],
      axisList: [],
      fieldList: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '部门',
          align: 'center',
          width: 150,
          dataIndex: 'departmentName',
          key: 'departmentName',
        },
        {
          title: '月份',
          align: 'center',
          width: 150,
          dataIndex: 'thisMonth',
          key: 'thisMonth',
        },
        {
          title: '离职人数',
          align: 'center',
          width: 150,
          dataIndex: 'resignPersonNumber',
          key: 'resignPersonNumber',
        },
        {
          title: '入职人数',
          align: 'center',
          width: 150,
          dataIndex: 'recordPersonNumber',
          key: 'recordPersonNumber',
        },
        {
          title: '月初在职人数',
          align: 'center',
          width: 150,
          dataIndex: 'prePersonNumber',
          key: 'prePersonNumber',
        },
        {
          title: '月末在职人数',
          align: 'center',
          width: 150,
          dataIndex: 'thisPersonNumber',
          key: 'thisPersonNumber',
        },
        {
          title: '离职率',
          align: 'center',
          width: 150,
          dataIndex: 'resignRate',
          key: 'item10',
        },
        {
          title: '入职率',
          width: 150,
          align: 'center',
          dataIndex: 'recordRate',
          key: 'recordRate',
        },
      ],
      dateFormat: 'YYYY-MM',
      setYearMonth: this.doHandleDate(),
      setYearMonthValue: this.doHandleDate(),
      tableList: [],
      url: {
        reportEmployeeRecordResign: '/online/api/reportEmployeeRecordResign',
        getEmployeeRecordResignReport: '/online/api/getEmployeeRecordResignReport',
      },
    }
  },
  computed: {
    // 列表请求参数
    listPostParams() {
      const params = { ...this.postParams }

      if (this.dataIndex !== undefined && this.dataIndex !== null) {
        const dataItem = this.axisList[this.dataIndex]
        delete params.type
        params.startTime = dataItem.type
        params.endTime = dataItem.type
      }

      return params
    },
  },
  mounted() {
    this.initAxis()
  },
  methods: {
    doHandleDate() {
      let myDate = new Date()
      let tYear = myDate.getFullYear()
      let tMonth = myDate.getMonth()
      let m = tMonth + 1
      if (m.toString().length == 1) {
        m = '0' + m
      }
      return tYear + '-' + m
    },
    /**
     * 搜索点击
     */
    searchClick(params) {
      this.postParams = params
      this.getRecordList()
    },
    /**
     * 获取相关列表
     */
    getRecordList(dataIndex) {
      this.dataIndex = dataIndex
      this.list = []
      this.loading = true
      biCustomerTotalListAPI(this.listPostParams)
        .then((res) => {
          this.loading = false
          const data = res.result || {}
          this.list = data.list || []
          this.getSummariesData(data.total)
        })
        .catch(() => {
          this.loading = false
        })
    },

    /** 图表 */
    initAxis() {
      this.chartAnalysis1 = this.echarts.init(document.getElementById('analysisBu1'))
      const param = {}
      param.setYearMonth = this.setYearMonth
      if(!this.isAllData){
        param.userLoginDepartmentId = this.$store.getters.departmentId
      }
      getAction(this.url.getEmployeeRecordResignReport, param).then((res) => {
        this.tableList = res.result.records
        let buList = []
        let seriesData = []
        let data1 = []
        let data2 = []
        let data3 = []
        let data4 = []
        res.result.records.forEach((e) => {
          buList.push(e.departmentName)
          if (e.departmentName != '汇总') {
            seriesData.push({
              name: e.departmentName,
              type: 'bar',
              barGap: '30%',
              emphasis: {
                focus: 'series',
              },
              data: [e.resignPersonNumber, e.recordPersonNumber, e.prePersonNumber, e.thisPersonNumber],
            })
          }
        })
        this.analysis1Option.legend.data = buList
        this.analysis1Option.series = seriesData
        this.$nextTick(() => {
          this.chartAnalysis1.setOption(this.analysis1Option, true)
        })
      })
    },
    handleDateChange(date, dateString) {
      this.setYearMonth = dateString
    },

    /**
     * 导出点击
     */
    exportClick() {
      this.requestExportInfo(biCustomerTotalListExportAPI, this.listPostParams)
    },
  },
}
</script>


<style lang="less" scoped>
/deep/ .ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  padding: 10px 4px;
}
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #2362fb;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}
.analysis {
  margin-top: 10px;
  .analysis-content {
    padding: 8px 10px;
    #analysisBu1 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
  }
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
  .axismain,
  #summaryAll1 {
    margin: 0 auto;
    width: 100%;
    height: 400px;
  }
}

.table-content {
  padding: 0 30px 20px 30px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
/deep/ .ant-table-wrapper {
  border: 1px solid #ebeef5;
}
/deep/ .ant-table-placeholder {
  display: none;
}
</style>

